import { fuseSearchFun, HostEnum, type GameJson } from "~/utils";
import { getServerCache } from "../plugins/cache";

/** 根据categoryType获取游戏数据 */
export default defineEventHandler(async (event): Promise<GameJson[]> => {
  const { hostName = HostEnum.localhost, categoryType } = await readBody(event);
  const { allGameJson = [] } = getServerCache().gameJsonDataSource[hostName];
  return fuseSearchFun({
    list: allGameJson,
    keys: ["type"],
    value: categoryType,
  });
});
